package com.euq.controller;

import com.euq.entity.Dict;

import com.euq.log.BusinessLog;
import com.euq.log.Log;
import com.euq.service.DictService;
import com.euq.utils.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/dict")
public class DictController {
    @Autowired
    private DictService dictService;
    private static final Logger log = LoggerFactory.getLogger(DictController.class);
    @GetMapping("/list")
    public Object list() {
        return dictService.list();
    }
    @PostMapping("update")
    @BusinessLog(logName = "修改字典",logType = "业务日志")
    public void update(Long id, String dictName, String value) {
        log.info("用户{}修改字典{}信息", SecurityUtils.getCurrentUser().getUsername(),dictName);
        dictService.update(id,dictName,value);
    }
    @PostMapping("insert")
    @BusinessLog(logName = "新增字典",logType = "业务日志")
    public void addDict(String dictName, String value) {
        log.info("用户{}新增字典{}", SecurityUtils.getCurrentUser().getUsername(),dictName);
        dictService.addDict(dictName, value);
    }
    @PostMapping("delete")
    @BusinessLog(logName = "删除字典",logType = "业务日志")
    public void deleteById(int id ) {
        log.info("用户{}删除字典", SecurityUtils.getCurrentUser().getUsername());
        dictService.deleteById(id);
    }
    @PostMapping("getDict")
    public Dict getDictByName(String name) {
        return dictService.getDictByName(name);
    }
}
